package bomberman.model;

import java.awt.Graphics;

import bomberman.MainGame;
import bomberman.util.CommonTouch;
import bomberman.util.Constants;
import bomberman.util.GameMap;

public class Man {
	private int x;
	private int y;
	private char direction;
	
	private boolean isLive = true;
	
	public Man(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	public void draw(Graphics g) {
		g.drawImage(GameMap.img_man, x, y, MainGame.jPanelIndex);
	}
	
	/**
	 * 人物移动
	 */
	public void move(){
		if(Constants.DOWN){
			y += Constants.SPEED;
			if (checkAllTouch()) {
				y -= Constants.SPEED;
			}
		}
		if(Constants.UP){
			y -= Constants.SPEED;
			if (checkAllTouch()) {
				y += Constants.SPEED;
			}
		}
		if(Constants.LEFT){
			x -= Constants.SPEED;
			if (checkAllTouch()) {
				x += Constants.SPEED;
			}
		}
		if(Constants.RIGHT){
			x += Constants.SPEED;
			if (checkAllTouch()) {
				x -= Constants.SPEED;
			}
		}
		
		// 若碰撞道具，则道具消失，且改变相应属性
		Property pro = CommonTouch.checkIfTouchProperty(x, y);
		if (pro != null) {
			pro.remove();
			pro.changeConstantsValue();
		}
	}
	
	
	public boolean checkAllTouch(){
		return CommonTouch.checkIfTouchBorder(x, y) 
				|| CommonTouch.checkIfTouchStone(x, y) 
				|| CommonTouch.checkIfTouchWall(x, y) 
				|| CommonTouch.checkIfTouchBom(x, y) ;
	}
	
	
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public char getDirection() {
		return direction;
	}

	public void setDirection(char direction) {
		this.direction = direction;
	}

	public boolean isLive() {
		return isLive;
	}

	public void setLive(boolean isLive) {
		this.isLive = isLive;
	}
	
}
